/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

$(document).ready(function(){
	//global vars
	var form = $("#customForm");
	var username = $("#username");
	var nameInfo = $("#nameInfo");
//	var email = $("#email");
//	var emailInfo = $("#emailInfo");
	var pass1 = $("#pass1");
	var pass1Info = $("#pass1Info");
//	var pass2 = $("#pass2");
//	var pass2Info = $("#pass2Info");
//	var message = $("#message");
	
	//On blur
	username.blur(validateUsername);
	//email.blur(validateEmail);
	pass1.blur(validatePass1);
//	pass2.blur(validatePass2);
	//On key press
	username.keyup(validateUsername);
	pass1.keyup(validatePass1);
//	pass2.keyup(validatePass2);
//	message.keyup(validateMessage);
	//On Submitting
	form.submit(function(){
		if(validateUsername() & validatePass1() )
			return true
		else
			return false;
	});
	
	//validation functions
	function validateUsername(){
		//if it's NOT valid
		if(username.val().length < 4){
			username.addClass("error");
			nameInfo.text("We want Adways ID with more than 3 letters!");
			nameInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			username.removeClass("error");
			nameInfo.text("What's your name?");
			nameInfo.removeClass("error");
			return true;
		}
	}
	function validatePass1(){
		//var a = $("#password1");
		//var b = $("#password2");

		//it's NOT valid
		if(pass1.val().length <3){
			pass1.addClass("error");
			pass1Info.text("Ey! Remember: At least 3 characters: letters, numbers and '_'");
			pass1Info.addClass("error");
			return false;
		}
		//it's valid
		else{			
			pass1.removeClass("error");
			pass1Info.text("At least 5 characters: letters, numbers and '_'");
			pass1Info.removeClass("error");
			validatePass2();
			return true;
		}
	}

});